<template>
	<view class="content">
		<button class="size" @tap="handel">获取当前Webview窗口对象的native层实例对象</button>
		<button class="size" @tap="newObject">创建实例对象</button>
		<button class="size" @tap="getAttribute">获取对象（类对象/实例对象）的属性值</button>
		<button class="size" @tap="requestPermissions">请求权限</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: "nick",
				text: "",
				localplayer: null,
				nwv: null
			}
		},
		methods: {
			handel() {
				this.nwv = plus.android.currentWebview();
				console.log("nwv=>", this.nwv)
				if (plus.nativeUI.alert("调用失败"))
					plus.android.invoke(this.nwv, "loadUrl", "http://www.dcloud.io/");

			},
			newObject() {
				var intent = plus.android.newObject("android.content.Intent");
				plus.nativeUI.alert("android.content.Intent")
			},
			getAttribute() {
				var Context = plus.android.importClass("android.content.Context");
				var ActivityManager = plus.android.importClass("android.app.ActivityManager");
				var mi = new ActivityManager.MemoryInfo();
				var activityService = plus.android.runtimeMainActivity().getSystemService(Context.ACTIVITY_SERVICE);
				activityService.getMemoryInfo(mi);
				// 获取mi对象的availMem属性值
				var memoryInfo = plus.android.getAttribute(mi, "availMem");
				plus.nativeUI.alert(JSON.stringify(memoryInfo))
			},
			requestPermissions() {
				plus.android.requestPermissions(['android.permission.ACCESS_FINE_LOCATION'], function(e) {
					if (e.deniedAlways.length > 0) { //权限被永久拒绝
						// 弹出提示框解释为何需要定位权限，引导用户打开设置页面开启
						plus.nativeUI.alert('Always Denied!!! ' + e.deniedAlways.toString());
					}
					if (e.deniedPresent.length > 0) { //权限被临时拒绝
						// 弹出提示框解释为何需要定位权限，可再次调用plus.android.requestPermissions申请权限
						plus.nativeUI.alert('Present Denied!!! ' + e.deniedPresent.toString());
					}
					if (e.granted.length > 0) { //权限被允许
						//调用依赖获取定位权限的代码
						plus.nativeUI.alert('Granted!!! ' + e.granted.toString());
					}
				}, function(e) {
					plus.nativeUI.alert('Request Permissions error:' + JSON.stringify(e));
				});


			},

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.size {
		margin: 30rpx 0;
	}
</style>
